﻿<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" CodeBehind="news_queryset_edit.aspx.cs"
    Inherits="Ccit.OA.NewsCenter.news_queryset_edit" %>
<%@ Register TagPrefix="ccit" Namespace="Ccit.ServerControls" Assembly="Ccit.ServerControls.ActionForm" %>

<%@ Register Assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="Microsoft.Web.UI.WebControls" TagPrefix="iewc" %>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>信息中心-信息条件编辑</title>
    <script language="javascript" src="../script/jquery.js" type="text/javascript"></script>

    <script language="javascript" src="../script/StringClass_Ext.js" type="text/javascript"></script>

    <script language="javascript" src="../script/jsonlib.js" type="text/javascript"></script>

    <script language="javascript" src="../script/jcontrol.js" type="text/javascript"></script>

    <script language="javascript" src="../script/jwindow.js" type="text/javascript"></script>
 
    <style type="text/css">
      .skin
        {
            border-right: buttonhighlight 2px outset;
            border-top: buttonhighlight 2px outset;
            font-size: 9pt;
            visibility: hidden;
            border-left: buttonhighlight 2px outset;
            width: 100px;
            cursor: default;
            border-bottom: buttonhighlight 2px outset;
            font-family: Arial, Helvetica, sans-serif;
            position: absolute;
            background-color: menu;
            text-align: left;
        }
        .menuitems
        {
            padding-right: 5px;
            padding-left: 5px;
            padding-top: 5px;
            padding-bottom: 5px;
        }
    </style>

   
    <script language="javascript" type="text/javascript">          
      <!--//通用用户多选页面
      function SelRange(ctrlUserId,ctrlUserName)
      {
        OpenUserMultiSelect(ctrlUserId,ctrlUserName,"0");
      }
      //取消
      function doCancel()
      {
         var PageSource=$get("_hidPageSource").value;
		 var vPageParam = "Type="+$get("_hidType").value+"&TABID="+document.getElementById("_hidTabId").value;
		 var encodeParam = base64encode(vPageParam);
         if(PageSource=="1")
            parent.document.location="news_submit_list.aspx?" + encodeParam;
         if(PageSource=="2")
           parent.document.location="news_search_frame.aspx?" + encodeParam;
         if(PageSource=="3")
           parent.document.location="news_list_manage.aspx?" + encodeParam;
      }
      function checkForm()
      {
         if($get("rdBefore").checked==true){
             $get("txtBeforeDay").readOnly=false;
         }else
         {
            $get("txtBeforeDay").readOnly=true;
            $get("txtBeforeDay").value="";
         }
         if($get("rdRange").checked){
            $get("txtBeginTime").readOnly=false;
            $get("txtEndTime").readOnly=false;           
         }else
         {
            $get("txtBeginTime").readOnly=true;
            $get("txtEndTime").readOnly=true; 
            $get("txtBeginTime").value="";
            $get("txtEndTime").value=""; 
         }
      }
      //获取单选值
      function selRadioButton()
      {
         var rdValue;
         if($get("rdAllTime").checked){
            rdValue=$get("rdAllTime").value;
         }
         if($get("rdNowDay").checked){
            rdValue=$get("rdNowDay").value;
         }
         if($get("rdNowWeek").checked){
            rdValue=$get("rdNowWeek").value;
         }
         if($get("rdNowMonth").checked){
            rdValue=$get("rdNowMonth").value;
         }
         if($get("rdBefore").checked){
                rdValue=$get("rdBefore").value;
         }
         if($get("rdRange").checked){
            rdValue=$get("rdRange").value;
         }
         return rdValue;
      }
      //层确定
      function divdoSave()
      {
          if(!checkCaluseName()) return ;
          if(!checkNum())return ;
          var MsClause={};
          MsClause.ClauseId=$get("_hidClauseId").value;
          MsClause.ClauseName=$get("txtClauseName").value;          
          MsClause.ClauseContent=getNewsXML();
          MsClause.ClauseType =( document.getElementById("_hidType").value != "") ? document.getElementById("_hidType").value : "0";
          // document.getElementById("_hidPageSource").value;
          var jsonExpr=JSON.stringify(MsClause,function(key,value){return value;});
          var addPlate="-1";
          if($get("cbkAddNews").checked){
             addPlate="1"; //选中复选框
          }
          var vType = document.getElementById("_hidType").value;
          var pageSource = document.getElementById("_hidPageSource").value;
          PageMethods.SaveFastClause(jsonExpr,addPlate,vType,pageSource,ClientCallBack);
      }
      //返回结果
		function ClientCallBack(vExeResult)
		{
		    var vNodeIdArray = vExeResult.split("_");
		    var type=vNodeIdArray[0];
		    switch(type){ 
		       case "saveQuery":
		         eval("var objResult="+vNodeIdArray[1]);
                 if(objResult.resFlag > 0){
                   alert(objResult.resMes);
                 }
                 $get("_hidClauseId").value=objResult.resColumnId;
                 hidden();
                 var vPageParam = "Type="+$get("_hidType").value+"&PageSource="+$get("_hidPageSource").value+"&TABID="+document.getElementById("_hidTabId").value;
                 var encodeParam = base64encode(vPageParam);
                 parent.frames[0].document.location="news_queryset_list.aspx?" + encodeParam;
                 break;
		    }
		    
		}
      //条件名称不为空
      function checkCaluseName()
      {
        var ClauseName=$get("txtClauseName").value;
        if(ClauseName==""){
           alert("条件名称不能为空");
           $get("txtClauseName").focus();
           return false;
        }
        return true;
      }
      
      var cNodeIds="";//记录所有选择复选框的id
      var ArrayNew = "";   //过滤后没有权限的id
      //获取条件内容
      function getNewsXML()
      {
         var strXml = "";
         strXml = "<QUERY><CAPTION><![CDATA[";
         strXml += $get("txtNewsTitle").value + "]]></CAPTION><CREATOR>";
         strXml += $get("hidUserId").value + "</CREATOR><PICFLAG>";
         var dropDownPicFlag = new DropDownList("ddlNavigationImg");
         strXml+=dropDownPicFlag.selectedValue+"</PICFLAG><TOPFLAG>";
         var dropDownTopSign = new DropDownList("ddlTopSign");
         strXml+=dropDownTopSign.selectedValue+"</TOPFLAG><CATEGORY>";
         FindCheckedFromNode();
         var vColIds = "";
         if(cNodeIds!="")
         {
           // cNodeIds=cNodeIds.substring(0,cNodeIds.length-1);
            Array.prototype.remove=function(dx)
            {
              if(isNaN(dx)||dx>this.length){return false;}
              for(var i=0,n=0;i<this.length;i++)
              {
                if(this[i]!=this[dx])
                {
                    this[n++]=this[i]
                }
              }
              this.length-=1
            }
            
            var ArrayNodeIds = cNodeIds.split(",");
            var vRangeCode = document.getElementById("_hidRangeColIds").value;           
            var ArrayRange = vRangeCode.split(",");
           
            for(var i = 0;i<ArrayRange.length;i++)
            {
                for(var j = 0; j<ArrayNodeIds.length;j++)
                {
                    if(ArrayRange[i] == "'"+ArrayNodeIds[j]+"'")
                    {
                       ArrayNew += (ArrayNew == "") ? ArrayNodeIds[j] : "," + ArrayNodeIds[j];
                    }
                }
            }
         }
         // alert(cNodeIds);
         // alert(ArrayNew+"------");
         
         
         strXml+=ArrayNew;
         cNodeIds="";
         strXml+="</CATEGORY><TIME TYPE=\""+selRadioButton()+"\">";
         if(selRadioButton()=="4"){
            strXml+=$get("txtBeforeDay").value;
         }
         if(selRadioButton()=="5"){
            strXml+=$get("txtBeginTime").value+"~"+$get("txtEndTime").value;
         }
         strXml+="</TIME><NEWSSTATUS>";
         var dropStatus=new DropDownList("ddlNewsStatus");
         strXml += dropStatus.selectedValue;
         strXml +="</NEWSSTATUS></QUERY>";
         return strXml;
       }
       
       function checkNum()
       {
          var diffDays=$get("txtBeforeDay").value;
          if(diffDays!=""&&!diffDays.IsNumber())
          {
             alert("天数须为数字");
             return false;
          }
          return true;
       }
       
       //窗口获取xml
       function getClauseContent()
       {
         if(!checkNum())
            return "";
         var strXml = "";
         strXml = "<QUERY><CAPTION><![CDATA[";
         strXml += $get("txtNewsTitle").value + "]]></CAPTION><CREATOR>";
         strXml += $get("hidUserId").value + "</CREATOR><PICFLAG>";
         var dropDownPicFlag = new DropDownList("ddlNavigationImg");
         strXml+=dropDownPicFlag.selectedValue+"</PICFLAG><TOPFLAG>";
         var dropDownTopSign = new DropDownList("ddlTopSign");
         strXml+=dropDownTopSign.selectedValue+"</TOPFLAG><CATEGORY>";
         FindCheckedFromNode();
         if(cNodeIds!="")
         {
           // cNodeIds=cNodeIds.substring(0,cNodeIds.length-1);
            
            Array.prototype.remove=function(dx)
            {
              if(isNaN(dx)||dx>this.length){return false;}
              for(var i=0,n=0;i<this.length;i++)
              {
                if(this[i]!=this[dx])
                {
                    this[n++]=this[i]
                }
              }
              this.length-=1
            }
            var ArrayNew = "";  
            var ArrayNodeIds = cNodeIds.split(",");
            var vRangeCode = document.getElementById("_hidRangeColIds").value;           
            var ArrayRange = vRangeCode.split(",");
           
            for(var i = 0;i<ArrayRange.length;i++)
            {
                for(var j = 0; j<ArrayNodeIds.length;j++)
                {
                    if(ArrayRange[i] == ArrayNodeIds[j])
                    {
                       ArrayNew += (ArrayNew == "") ? ArrayNodeIds[j] : "," + ArrayNodeIds[j];
                    }
                }
            }
            
         }
         
         strXml+=ArrayNew;
         cNodeIds="";
         strXml+="</CATEGORY><TIME TYPE=\""+selRadioButton()+"\">";
         if(selRadioButton()=="4"){
            strXml+=$get("txtBeforeDay").value;
         }
         if(selRadioButton()=="5"){
            strXml+=$get("txtBeginTime").value+"~"+$get("txtEndTime").value;
         }
         strXml+="</TIME><NEWSSTATUS>";
         strXml +="</NEWSSTATUS></QUERY>";
         return strXml;
       }
       
       
        //弹出及隐藏层
        function show() 
        { 
          var divId=document.getElementById('message');
          divId.style.display = "block"; 
        } 
        function hidden() 
        { 
           document.getElementById("message").style.display = "none"; 
        }
        

     // -->
    </script>
</head>
<body>
    <ccit:ActionForm id="form1" runat="server">
    
    <input type="hidden" runat="server" id="_hidRangeColIds" />
    
    <input type="hidden" id="_hidTabId" runat="server" />
    <%--<input type="hidden" id="_hidWhereClause" runat="server" />--%>
   
    <input type="hidden" value="" id="_hidPageSource" runat="server" />
    <!--类型-->
    <input type="hidden" value="" id="_hidType" runat="server" />
    <!--条件xml串-->
    <input type="hidden" value="" id="_hidClauseXML" runat="server" />
    <!--操作页面-->
    <input type="hidden" value="" id="_hidOper" runat="server" />
    <!--编辑主键clauseId-->
    <input type="hidden" value="" id="_hidClauseId" runat="server" />
    
    <!--保存条件的层-->
    <div id="message" style="display: none; text-align: center; width: 250px; height: 100px;
        border: 1px #919B9C solid; position: absolute; top: 160px; left: 100px; background: #F8F8F5;">
        <div style="padding-top: 10px;">
            <font style="color: Red">*</font>条件名称
            <asp:TextBox ID="txtClauseName" runat="server" CssClass="input"></asp:TextBox>
        </div>
        <div style="padding-top: 5px;">
            <asp:CheckBox ID="cbkAddNews" CssClass="checkbox" runat="server" Text="同时加入到信息窗口" />
        </div>
        <div style="padding-top: 5px;">
            <input type="button" id="btndivOk" class="button" value="确定" runat="server" onclick="divdoSave()" />&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="button" id="btndivCancle" class="button" value="取消" runat="server" onclick="javascript:hidden()" />
        </div>
     </div>
     <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
     </asp:ScriptManager>
     <table class="tableborder" border="0" cellpadding="0" cellspacing="0" width="98%" align="center">
        <tr>
           <td width="10%" class="pformleft" align="right">
               <nobr>信息标题包含</nobr>
           </td>
           <td width="90%" colspan="3" class="pformright">
               <asp:TextBox ID="txtNewsTitle" CssClass="input" Width="99.8%" runat="server"></asp:TextBox>
           </td>
        </tr>
        <tr>
           <td width="10%" class="pformleft" align="right">
               <nobr>发布人</nobr>
           </td>
           <td width="90%" colspan="3" class="pformright">
               <input type="hidden" value="" id="hidUserId" runat="server" />
               <asp:TextBox ID="txtPubPerson" CssClass="inputReadonly" ReadOnly Width="91%" runat="server"></asp:TextBox>
               <img src="../images/edit_logo/SEARCH.GIF" width="25" onclick="SelRange('hidUserId','txtPubPerson')" height="25" border="0" />
           </td>
        </tr>
        <tr>
           <td width="10%" class="pformleft" align="right">
               <nobr>导航图片标志</nobr>
           </td>
           <td width="90%" colspan="3" class="pformright">
               <nobr>
                   <asp:DropDownList ID="ddlNavigationImg" Width="38%" CssClass="select" runat="server">
                        <asp:ListItem Value="">全部</asp:ListItem>
                        <asp:ListItem Value="1">是</asp:ListItem>
                        <asp:ListItem Value="0">否</asp:ListItem> 
                   </asp:DropDownList>&nbsp;&nbsp;&nbsp;&nbsp;
                   置顶标志
                   <asp:DropDownList ID="ddlTopSign" Width="38%"  CssClass="select"  runat="server">
                        <asp:ListItem Value="">全部</asp:ListItem>
                        <asp:ListItem Value="1">是</asp:ListItem>
                        <asp:ListItem Value="0">否</asp:ListItem>  
                   </asp:DropDownList>   
               </nobr>
            </td>
        </tr>
        <tr runat="server" id="trNewsStatu">
            <td width="10%" class="pformleft" align="right">
                <nobr>信息状态</nobr>
            </td>
            <td width="90%" colspan="3" class="pformright">
                <asp:DropDownList ID="ddlNewsStatus" Width="38%" CssClass="select"  runat="server">
                    <asp:ListItem Value="">全部</asp:ListItem>
                    <asp:ListItem Value="0">未提交</asp:ListItem>
                    <asp:ListItem Value="1">已提交</asp:ListItem>
                    <asp:ListItem Value="2">已发布</asp:ListItem>
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td class="pformleft" valign="top" colspan="4" align="center">
               <nobr>
                   <fieldset style="width:49%; height:100%; text-align:left" >
                     <legend>栏目范围</legend>
                         <table border="0" cellpadding="0" cellspacing="0" width="100%">
                           <tr>
                             <td>
                               <div style="height:150px; overflow-y:auto;"><iewc:TreeView ID="tvColumn" runat="server"></iewc:TreeView></div>   
                             </td>
                           </tr>
                         </table>
                   </fieldset>
                   <fieldset style="width:49%;height:100%;">
                     <legend>时间范围</legend>
                       <table border="0" cellpadding="0" cellspacing="0" width="100%">
                         <tr>
                           <td colspan="3">
                             <input id="rdAllTime" class="radio" type="radio" name="date" value="0" checked runat="server" onclick="checkForm()"> 全部时间范围
                           </td>
                         </tr>
                         <tr>
                           <td  colspan="3">
                              <input id="rdNowDay" class="radio" type="radio" name="date" value="1"   runat="server" onclick="checkForm()"> 当天          
                              <input id="rdNowWeek" class="radio" type="radio" name="date" value="2"  runat="server" onclick="checkForm()"> 当周           
                              <input id="rdNowMonth" class="radio" type="radio" name="date" value="3"  runat="server" onclick="checkForm()"> 当月          
                           </td>
                        </tr>
                        <tr>
                          <td colspan="3">
                             <input id="rdBefore" class="radio" type="radio" name="date" value="4"  runat="server" onclick="checkForm()"> 之前         &nbsp;   
                             <asp:TextBox runat="server" id="txtBeforeDay" CssClass="input" Width="50px"  ReadOnly ></asp:TextBox> 天以内</td>                      
                        </tr>
                        <tr>
                          <td colspan="3"><input id="rdRange" class="radio" type="radio" name="date" value="5"  runat="server" onclick="checkForm()"> 指定时间范围</td>      
                        </tr>
                        <tr>                      
                          <td colspan="3"> &nbsp;从 
                            <asp:TextBox runat="server" id="txtBeginTime" CssClass="input" ReadOnly></asp:TextBox>               
	                        <IMG class="getdate" id="IMG1" title="选择日期" src="../images/toolbar/Calendar.gif" relaobj="txtBeginTime">
                           </td>                      
                        </tr>
                        <tr>                      
                          <td colspan="3"> &nbsp;到 <asp:TextBox runat="server" CssClass="input" ReadOnly id="txtEndTime"></asp:TextBox>
                           <IMG class="getdate" id="IMG2" title="选择日期" src="../images/toolbar/Calendar.gif" relaobj="txtEndTime">
                          </td>                      
                        </tr>
                      </table>
                  </fieldset>   
             </nobr>
            </td>
        </tr>
        <tr class="pformstrip" id="trButton" runat="server">
            <td colspan="4" align="center">
                <asp:Button ID="btnSearch" runat="server"  Text="执行查询" CssClass="button" onclick="btnSearch_Click" />
                &nbsp;
                <input type="button" id="btnSaveCont" class="button" runat="server" value="保存条件" onclick="show()" />
                &nbsp;
                <input type="button" id="btnCancel" class="button"  runat="server" value="取消" onclick="doCancel()" />
                &nbsp;
            </td>
        </tr>
    </table>
    
    
    <script type="text/javascript" language="javascript">  
		
        //oncheck事件
        function tree_oncheck(tree)
        {
         var node=tree.getTreeNode(tree.clickedNodeIndex);
         var Pchecked=tree.getTreeNode(tree.clickedNodeIndex).getAttribute("checked");
         setcheck(node,Pchecked);
        }
        //设置子节点选中
        function setcheck(node,Pc)
        {
         var i;
         var ChildNode=new Array();
         ChildNode=node.getChildren();
         
         if(parseInt(ChildNode.length)==0)
          return;
         else
         {
           for(i=0;i<ChildNode.length;i++)
           {
             var cNode;
             cNode=ChildNode[i];
             if(parseInt(cNode.getChildren().length)!=0)
             setcheck(cNode,Pc);
             cNode.setAttribute("checked",Pc);
           }
          }
        } 
     
        //获取所有选中节点
         function FindCheckedFromNode(node)
         {
            var nodes = new Array();
              
            if(node==null){
               var node=tvColumn.getTreeNode("0");   
               nodes = node.getChildren();
            }
            else
            {
               nodes = node.getChildren();
            }
            for (var i = 0; i < nodes.length; i++) {
              var cNode=nodes[i];
              if (cNode.getAttribute("checked")){
                 var array=cNode.getAttribute("ID").split("_");
                 if(array[0]!="")
                   cNodeIds +=array[0]+",";
            }
            if (parseInt(cNode.getChildren().length) != 0 )
                  FindCheckedFromNode(cNode);
            }
        }
    </script>
    </ccit:ActionForm>
</body>
</html>
